<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
  <head>

    <title>My JSP 'list_task.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

	  <div th:replace="~{commons/script::script}"></div>
  </head>
  	
  <body>
  <div>
	  <span>视图：</span><span onclick="return whole()" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">全部</span>|
	  <span onclick="return myTask()" class="easyui-linkbutton" data-options="plain:true">我的任务</span>|
	  <span onclick="return myFenPei()" class="easyui-linkbutton" data-options="plain:true">我分配的任务</span>
<!--	  <span onclick="return transformed()" class="easyui-linkbutton" data-options="plain:true">已转化的线索</span>-->
	  &nbsp;&nbsp;&nbsp;
	  <span onclick="return weiQiDong()" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">未启动</span>|
	  <span onclick="return tuiChi()" class="easyui-linkbutton" data-options="plain:true">推迟</span>|
	  <span onclick="return jinXingZhong()" class="easyui-linkbutton" data-options="plain:true">进行中</span>|
	  <span onclick="return yiWanCheng()" class="easyui-linkbutton" data-options="plain:true">已完成</span>|
	  <span onclick="return yiGuanBi()" class="easyui-linkbutton" data-options="plain:true">已关闭</span>|
	  <span onclick="return dayJieZhi()" class="easyui-linkbutton" data-options="plain:true">今日截止</span>|
	  <span onclick="return weekJieZhi()" class="easyui-linkbutton" data-options="plain:true">本周截止</span>|
	  <span onclick="return monthJieZhi()" class="easyui-linkbutton" data-options="plain:true">本月截止</span>|
	  <span onclick="return zuiJinCreate()" class="easyui-linkbutton" data-options="plain:true">最近分配</span>|
	  <span onclick="return zuiJinUpdate()" class="easyui-linkbutton" data-options="plain:true">最近更新</span>|
<!--	  <span onclick="return huishouzhan('/task/toListTaskHuishou')" class="easyui-linkbutton" data-options="iconCls:'icon-recover_deleted',plain:true">回收站</span>-->
	  &nbsp;<a href="/task/toListTaskHuishou" class="easyui-linkbutton" data-options="iconCls:'icon-recover_deleted',plain:true">回收站</a>
  </div>
  	<div>
  		<select  name="taskVo" class="easyui-combobox theme-textbox-radius" style="width:120px" id="select">
  			<option value="1">任意字段</option>
  			<option value="2">主题</option>
  			<option value="3">创建者</option>
  			<option value="4">负责人</option>
  			<option value="5">优先级</option>
  		</select>
  		<select name="taskVo.creatorUsername" class="easyui-combobox theme-textbox-radius" style="width:100px" >
  			<option value="1">包含</option>
  			<option value="2">人名</option>
  		</select>
  		<input name="subject" type="text" class="easyui-textbox theme-textbox-radius">
  		<a href="javascript:void(0);" onclick="return searchs()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
  	</div>
 
    <table id="taskList"class="easyui-datagrid">
    	
    </table>
  
    <div id="toolbar">
    	<a href="javascript:void(0);" onclick="return add('/task/toAddTask')" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建</a>
    	<a href="javascript:void(0);" onclick="return del('/task/deleteTask')" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
		<a href="javascript:void(0);" onclick="return close('/task/closeTask')" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">关闭</a>
    	
    </div>
    
  </body>
  <script type="text/javascript">
	  //查询全部任务
	  function whole(url){
		  $("#taskList").datagrid("load",{})
	  }
	  //查询我的任务
	  function myTask(){
		  $("#taskList").datagrid("load",{
			  "fuzeren":"me"
		  })

	  }
	  //我分配的任务
	  function myFenPei(){
		  $("#taskList").datagrid("load",{
			  "fuzeren":"fenpei"
		  })
	  }
	  //未启动
	  function weiQiDong(){
		  $("#taskList").datagrid("load",{
			  "status":"wei"
		  })
	  }
	  //推迟
	  function tuiChi(){
		  $("#taskList").datagrid("load",{
			  "status":"tui"
		  })
	  }
	  //进行中
	  function jinXingZhong(){
		  $("#taskList").datagrid("load",{
			  "status":"jin"
		  })
	  }
	  //已完成
	  function yiWanCheng(){
		  $("#taskList").datagrid("load",{
			  "status":"wan"
		  })
	  }
	  //已关闭
	  function yiGuanBi(){
		  $("#taskList").datagrid("load",{
			  "status":"guan"
		  })
	  }
	  //今日截止
	  function dayJieZhi(){
		  $("#taskList").datagrid("load",{
			  "jiezhi":"day"
		  })
	  }
	  //本周截止
	  function weekJieZhi(){
		  $("#taskList").datagrid("load",{
			  "jiezhi":"week"
		  })
	  }
	  //本月截止
	  function monthJieZhi(){
		  $("#taskList").datagrid("load",{
			  "jiezhi":"month"
		  })
	  }
	  //最近分配
	  function zuiJinCreate(){
		  $("#taskList").datagrid("load",{
			  "zuijin":"create"
		  })
	  }
	  //最近更新
	  function zuiJinUpdate(url){
		  $("#taskList").datagrid("load",{
			  "zuijin":"update"
		  })
	  }

  		function add(url){
  			parent.parent.openTopWindow(
  			{
  				width :500,
  				height:700,
  				"title":"修改任务",
  				"url":url,
  				close:function(){
  					$("#taskList").datagrid("reload")
  				}
  				
  			}
  			)
  		}
  		function searchs(){
  			$("#taskList").datagrid("load",{
  			 "subject" : $("input[name=subject]").val(),
			 "select":$("#select").val()
  			})
  		}
  		function del(url){
			var rows=$("#taskList").datagrid("getChecked");
			if(!rows.length){
				$.messager.alert("警告","请选择要删出的任务");
				return ;
			}
			$.messager.confirm("警告","数据删除无法恢复",function(b){
				if(b){
				var ids=new Array();
				$.each(rows,function(index,obj){
						ids.push(obj.id)
				})
					ids=ids.join(",")
					$.post(url,
					{"ids":ids},
					function(data){
					if(data.success && data){
						$.messager.alert("提示",data.message)
						$("#taskList").datagrid("reload");
						return 
					}
						$.messager.alert("提示",data.message)	
					
					},
					"json"
					)	
				}
			})
  		}
  		function edit(url){
  			var rows=$("#taskList").datagrid("getChecked");
  			if(!rows.length){
  				$.messager.alert("提示","请选择要修改的任务");
  				return ;
  			}
  			var taskId=rows[0].taskid;
  			parent.openTopWindow({
  				width:500,
  				height:700,
  				title:"修改任务",
  				"url":url+"?taskVo.taskid="+taskId,
  				close:function(){
  					$("#taskList").datagrid("reload")
  				}
  			})
  		}
		$(function(){
			$("#taskList").datagrid({
				url:"/task/listTask",
				pagination:true,
				toolbar:"#toolbar",
				fitColumns:true,
				idField:"taskid",
				rownumbers:true,
				columns :[
						[
					{field:"id",title:"选择",checkbox:true},
					{field:"subject" ,title:"主题",width:1},
					{field:"aboutUsers",title:"相关信息",width:3},
					{field:"ownerUsername",title:"负责人",width:1},
					{field:"status",title:"状态",width:1},
					{field:"priority",title:"优先级",width:1},
					{field:"creatorUsername",title:"创建者",width:1},
					{field:"dueDate" ,title:"截止日期",width:3},
					{field:"operation",width:2,title:"操作",formatter:function(value,rowData,index){
					return "<a href='javascript:void(0);' onclick='see("+rowData.id+")'>查看</a>"+
							"<a href='javascript:void(0);' onclick='modify("+rowData.id+")'>修改</a>"+
							"<a href='javascript:void(0);' onclick='guanbi("+rowData.id+")'>关闭</a>"
					}},		
					
					
				]
				],
				
				loadFilter:function(data){
				return {"total":data.data.totalRows,"rows":data.data.result}
				}	
				
			})		
		}) 
			
			function see(id){
				// $("#taskList").datagrid("selectRow",index);
				// var row=$("#taskList").datagrid("getSelected");
				// var id=row.taskid;
				parent.parent.openTopWindow({
				width:500 ,
				height:700 ,
				title:"查看" ,
				url: "/task/seeTask?id="+id,
				close:function(){
				$("#taskList").datagrid("reload")
				}
				})
				
			}
			function modify(id){
				// $("#taskList").datagrid("selectRow",index)
				// var row=$("#taskList").datagrid("getSelected")
				// var id=row.taskid;
				parent.parent.openTopWindow(
				{
					width:500,
					height:700,
					title:"修改任务",
					url:"/task/toUpdateTask"+"?id="+id,
					close:function(){
						$("#taskList").datagrid("reload")
					}
				}
				)
			}
			function guanbi(id){
		  		$.post("/task/closeTask",{"id":id},function(data){
					  if(data.success && data){
						  $.messager.alert("提示",data.message)
						  $("#taskList").datagrid("reload");
						  return;
					  }
					  $.messager.alert("提示",data.message)
				})
			}
  
  </script>
</html>
